package com.topsmob;

import com.topsmob.piepline.XunLeiPiePline;
import com.topsmob.processer.XunLeiProcesser;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.monitor.SpiderMonitor;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.Properties;

/**
 * Created by GameLee on 2017/7/11.
 */
public class XunLeiStart
{
    public static String domain;
    public static String startUrl;
    public static String userId;
    public static String userName;
    public static String lastPostId;
    public static String saveUrl;
    public static String listUrl;
    public static Spider spider;
    public static  boolean isFirst = true;
    public static Properties properties;
    public static void main(String[] args) {
        try {
            properties = new Properties();
            InputStream inputStream = new FileInputStream(System.getProperty("user.dir") + File.separator + "xunlei.properties");
            properties.load(inputStream);
            inputStream.close();
            domain = properties.get("domainUrl").toString();
            startUrl = properties.get("startUrl").toString();
            lastPostId = properties.get("lastPostId").toString();
            userId = properties.get("userId").toString();
            userName = properties.get("userName").toString();
            saveUrl = properties.get("saveUrl").toString();
            listUrl = properties.get("listUrl").toString();
            System.out.println("domainUrl:" + domain + ";startUrl=" + startUrl +
                    ";lastPostId=" + lastPostId + ";userId=" + userId+"; userName= "+userName);
            System.out.println("配置文件加载成功");

            spider = Spider.create(new XunLeiProcesser()).addUrl(startUrl).thread(10);
            SpiderMonitor.instance().register(spider);
            spider.start();
        }catch (Exception e){

        }
    }
}
